//
//  UICustomView.m
//  TTAddressBook
//
//  Created by iphonekf2 on 12-1-12.
//  Copyright (c) 2012Âπ?__MyCompanyName__. All rights reserved.
//

#import "UIBigCustomView.h"
#import "imagePath.h"
#import "define.h"

@implementation UIBigCustomView

- (id)initWithFrame:(CGRect)frame choose:(NSInteger)choose_Flag;
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code  
        self.backgroundColor = [UIColor clearColor];
        menuImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 250, 190)];
        menuImageView.backgroundColor = [UIColor clearColor];
        menuImageView.image = [UIImage imageNamed:@"lbg.png"];
        menuImageView.alpha = 0.95;
        [self addSubview:menuImageView];
        menuImageView.tag = MENUVIEW_TAG;
        [menuImageView release];   
        
        btnDay = [UIButton buttonWithType:UIButtonTypeCustom];
        btnDay.frame =CGRectMake(1, 9, 62, 70);
        [btnDay setImage:[UIImage imageNamed:@"day1.png"] forState:(UIControlStateNormal) ];
        [btnDay setImageEdgeInsets:UIEdgeInsetsMake(10, 15, 30, 15)]; 
        btnDay.titleLabel.font = [UIFont systemFontOfSize:11];
        [btnDay setTitle:@"日视图" forState:UIControlStateNormal];
        [btnDay setTitleEdgeInsets:UIEdgeInsetsMake(40, -60, 5, 0)]; 
        btnDay.tag = 1;
        [btnDay addTarget:self action:@selector(clickBtn:)  forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:btnDay];  
        
        btnWeek = [UIButton buttonWithType:UIButtonTypeCustom];
        btnWeek.frame =CGRectMake(62, 9, 62, 70);
        [btnWeek setImage:[UIImage imageNamed:@"week.png"] forState:(UIControlStateNormal) ];
        [btnWeek setImageEdgeInsets:UIEdgeInsetsMake(10, 15, 30, 15)]; 
        btnWeek.titleLabel.font = [UIFont systemFontOfSize:11];
        [btnWeek setTitle:@"周视图" forState:UIControlStateNormal];
        [btnWeek setTitleEdgeInsets:UIEdgeInsetsMake(40, -60, 5, 0)]; 
        btnWeek.tag = 2;
        [btnWeek addTarget:self action:@selector(clickBtn:)  forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:btnWeek];
        
        btnMonth = [UIButton buttonWithType:UIButtonTypeCustom];
        btnMonth.frame =CGRectMake(126, 9, 62, 70);
        [btnMonth setImage:[UIImage imageNamed:@"month.png"] forState:(UIControlStateNormal) ];
        [btnMonth setImageEdgeInsets:UIEdgeInsetsMake(10, 15, 30, 15)]; 
        btnMonth.titleLabel.font = [UIFont systemFontOfSize:11];
        [btnMonth setTitle:@"月视图" forState:UIControlStateNormal];
        [btnMonth setTitleEdgeInsets:UIEdgeInsetsMake(40, -60, 5, 0)]; 
        btnMonth.tag = 3;
        [btnMonth addTarget:self action:@selector(clickBtn:)  forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:btnMonth];
        
        btnList = [UIButton buttonWithType:UIButtonTypeCustom];
        btnList.frame =CGRectMake(188, 9, 61, 70);
        [btnList setImage:[UIImage imageNamed:@"list1.png"] forState:(UIControlStateNormal) ];
        [btnList setImageEdgeInsets:UIEdgeInsetsMake(10, 15, 30, 15)]; 
        btnList.titleLabel.font = [UIFont systemFontOfSize:11];
        [btnList setTitle:@"列表视图" forState:UIControlStateNormal];
        [btnList setTitleEdgeInsets:UIEdgeInsetsMake(40, -60, 5, 0)]; 
        btnList.tag = 4;
        [btnList addTarget:self action:@selector(clickBtn:)  forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:btnList];
        
        
//        btnToday = [UIButton buttonWithType:UIButtonTypeCustom];
//        btnToday.frame =CGRectMake(0, 79, 80, 40);
//        btnToday.titleLabel.font = [UIFont systemFontOfSize:12];
//        [btnToday setTitle:@"回今天" forState:UIControlStateNormal];
//        //[btnToday setTitleEdgeInsets:UIEdgeInsetsMake(40, -60, 5, 0)]; 
//        btnToday.tag = 10;
//        [btnToday addTarget:self action:@selector(clickBtnAll:)  forControlEvents:UIControlEventTouchUpInside];
//        [self addSubview:btnToday];
        
        btnAllItem = [UIButton buttonWithType:UIButtonTypeCustom];
        btnAllItem.frame =CGRectMake(0, 79, 250, 40);
        btnAllItem.titleLabel.font = [UIFont systemFontOfSize:12];
        [btnAllItem setTitle:@"全部日程" forState:UIControlStateNormal];
        //[btnAllItem setTitleEdgeInsets:UIEdgeInsetsMake(40, -60, 5, 0)]; 
        btnAllItem.tag = 11;
        [btnAllItem addTarget:self action:@selector(clickBtnAll:)  forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:btnAllItem];
        
        btn1 = [UIButton buttonWithType:UIButtonTypeCustom];
        btn1.frame =CGRectMake(0, 119, 50, 70);
        [btn1 setImage:[UIImage imageNamed:@"pink.png"] forState:(UIControlStateNormal) ];
        [btn1 setImageEdgeInsets:UIEdgeInsetsMake(10, 15, 30, 15)]; 
        btn1.titleLabel.font = [UIFont systemFontOfSize:11];
        [btn1 setTitle:@"计划" forState:UIControlStateNormal];
        [btn1 setTitleEdgeInsets:UIEdgeInsetsMake(40, -10, 5, 0)]; 
        //[btn1 setBackgroundColor:[UIColor blackColor]];
        btn1.tag = 12;
        [btn1 addTarget:self action:@selector(clickBtnAll:)  forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:btn1];
        
        btn2 = [UIButton buttonWithType:UIButtonTypeCustom];
        btn2.frame =CGRectMake(50, 119, 50, 70);
        [btn2 setImage:[UIImage imageNamed:@"blue.png"] forState:(UIControlStateNormal) ];
        [btn2 setImageEdgeInsets:UIEdgeInsetsMake(10, 15, 30, 15)]; 
        btn2.titleLabel.font = [UIFont systemFontOfSize:11];
        [btn2 setTitle:@"记录" forState:UIControlStateNormal];
        [btn2 setTitleEdgeInsets:UIEdgeInsetsMake(40, -10, 5, 0)]; 
        //[btn2 setBackgroundColor:[UIColor blackColor]];
        btn2.tag = 13;
        [btn2 addTarget:self action:@selector(clickBtnAll:)  forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:btn2];
        
        btn3 = [UIButton buttonWithType:UIButtonTypeCustom];
        btn3.frame =CGRectMake(100, 119, 50, 70);
        [btn3 setImage:[UIImage imageNamed:@"green.png"] forState:(UIControlStateNormal) ];
        [btn3 setImageEdgeInsets:UIEdgeInsetsMake(10, 15, 30, 15)]; 
        btn3.titleLabel.font = [UIFont systemFontOfSize:11];
        [btn3 setTitle:@"生日" forState:UIControlStateNormal];
        [btn3 setTitleEdgeInsets:UIEdgeInsetsMake(40, -10, 5, 0)]; 
        //[btn3 setBackgroundColor:[UIColor blackColor]];
        btn3.tag = 14;
        [btn3 addTarget:self action:@selector(clickBtnAll:)  forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:btn3];
        
        btn4 = [UIButton buttonWithType:UIButtonTypeCustom];
        btn4.frame =CGRectMake(150, 119, 50, 70);
        [btn4 setImage:[UIImage imageNamed:@"orange.png"] forState:(UIControlStateNormal) ];
        [btn4 setImageEdgeInsets:UIEdgeInsetsMake(10, 15, 30, 15)]; 
        btn4.titleLabel.font = [UIFont systemFontOfSize:11];
        [btn4 setTitle:@"缴费日" forState:UIControlStateNormal];
        [btn4 setTitleEdgeInsets:UIEdgeInsetsMake(40, -10, 5, 0)]; 
        //[btn4 setBackgroundColor:[UIColor blackColor]];
        btn4.tag = 15;
        [btn4 addTarget:self action:@selector(clickBtnAll:)  forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:btn4];
        
        btn5 = [UIButton buttonWithType:UIButtonTypeCustom];
        btn5.frame =CGRectMake(200, 119, 50, 70);
        [btn5 setImage:[UIImage imageNamed:@"brown.png"] forState:(UIControlStateNormal) ];
        [btn5 setImageEdgeInsets:UIEdgeInsetsMake(10, 15, 30, 15)]; 
        btn5.titleLabel.font = [UIFont systemFontOfSize:11];
        [btn5 setTitle:@"活动" forState:UIControlStateNormal];
        [btn5 setTitleEdgeInsets:UIEdgeInsetsMake(40, -10, 5, 0)]; 
        //[btn5 setBackgroundColor:[UIColor blackColor]];
        btn5.tag = 16;
        [btn5 addTarget:self action:@selector(clickBtnAll:)  forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:btn5]; 
    }
    chooseFlag = choose_Flag;
//    NSInteger flag1,flag2;
//    flag1 = choose_Flag / 10;
//    flag2 = choose_Flag % 10;
//    switch (flag1) {
//        case 1:
//            btnDay.backgroundColor = [UIColor blackColor];
//            break;
//        case 2:
//            btnWeek.backgroundColor = [UIColor blackColor];
//            break;
//        case 3:
//            btnMonth.backgroundColor = [UIColor blackColor];
//            break;
//        case 4:
//            btnList.backgroundColor = [UIColor blackColor];
//            break;
//        default:
//            break;
//    }
//    switch (flag2) {
//        case 1:
//            btnAllItem.backgroundColor = [UIColor blackColor];
//            break;
//        case 2:
//            btn1.backgroundColor = [UIColor blackColor];
//            break;
//        case 3:
//            btn2.backgroundColor = [UIColor blackColor];
//            break;
//        case 4:
//            btn3.backgroundColor = [UIColor blackColor];
//            break;
//        case 5:
//            btn4.backgroundColor = [UIColor blackColor];
//            break;
//        case 6:
//            btn5.backgroundColor = [UIColor blackColor];
//            break;
//        default:
//            break;
//    }
    return self;
}
-(void) clickBtn :(id)sender{
    btnDay.backgroundColor = [UIColor clearColor];
    btnWeek.backgroundColor = [UIColor clearColor];
    btnMonth.backgroundColor = [UIColor clearColor];
    btnList.backgroundColor = [UIColor clearColor];
    [(UIButton*) sender setBackgroundColor:[UIColor blackColor]];
    chooseFlag = chooseFlag % 10 + ((UIButton*) sender).tag *10;
    [viewDelegate ChooseWithFlagNumber :chooseFlag];
}
-(void) clickBtnAll :(id)sender{
    btnAllItem.backgroundColor = [UIColor clearColor];
    btn1.backgroundColor = [UIColor clearColor];
    btn2.backgroundColor = [UIColor clearColor];
    btn3.backgroundColor = [UIColor clearColor];
    btn4.backgroundColor = [UIColor clearColor];
    btn5.backgroundColor = [UIColor clearColor];
    [(UIButton*) sender setBackgroundColor:[UIColor blackColor]];
    if (((UIButton*) sender).tag %10==0) {
      chooseFlag = ((chooseFlag / 10)*10 + chooseFlag % 10)*10;  
    }
    else
      chooseFlag = (chooseFlag / 10)*10 + ((UIButton*) sender).tag %10;
    [viewDelegate ChooseWithFlagNumber :chooseFlag];
}

-(void)set_Delegate:(id)delegate{
    viewDelegate = delegate;
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    CGPoint pos = [[touches anyObject] locationInView:self];
    [self ShowView: pos];    
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
    CGPoint pos = [[touches anyObject] locationInView:self];
    [self ShowView: pos]; 
    
}


- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
    //btnBackGround.hidden = YES; 
    [viewDelegate ChooseWithFlag:chooseFlag];
}

- (void) ShowView :(CGPoint) pos{
    chooseFlag = 0;
//    if ((pos.x< 0)||(pos.x>127)) {
//        btnBackGround.hidden = YES; 
//        return;
//    }
//    
//    if ((pos.y < 49) && (pos.y > 0)){
//        btnBackGround.frame = CGRectMake(0, 9, 127, 38);
//        btnBackGround.hidden = NO;
//        chooseFlag = 1;
//    }
//    else  if ((pos.y > 49) && (pos.y < 87)){
//        btnBackGround.frame = CGRectMake(0, 49, 127, 38);
//        btnBackGround.hidden = NO;
//        chooseFlag = 2;
//    }
//    else{
//        btnBackGround.hidden = YES; 
//    }
}

-(void) dealloc{

}



/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
